import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.GridLayout;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import javax.swing.JApplet;
import javax.swing.*;
import javax.swing.border.Border;
import java.awt.event.ActionEvent;


/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Window.java
 *
 * Created on Jan 4, 2012, 6:52:45 PM
 */
/**
 *
 * @author Figueroa
 */
public class Window extends javax.swing.JApplet implements MouseListener, MouseMotionListener {

    /** Initializes the applet Window */
    @Override
    public void init() {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(Window.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Window.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Window.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Window.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the applet */
    
             this.setSize(550, 500);
             resize(size().width < 200 ? 200 : size().width,
	     size().height < 200 ? 200 : size().height);
             
     
         

        initComponents();
        bg.add(jToggleButton1);
        bg.add(jToggleButton2);
  


        
        
     Graphics g=getGraphics();
        interfaz(g);
     
    }
    
    private Board tablero;
  
    public void interfaz(Graphics g){
    
      toolbox.setLayout(new GridLayout(6,2));
      toolbox.setPreferredSize(new java.awt.Dimension(300,200));
      toolbox.setMaximumSize(toolbox.getPreferredSize());
      tablero = new Board();
      tablero.setSize(450, 450);
      tablero.addMouseListener(this);
      tablero.addMouseMotionListener(this);
      tablero.paint(g);
    
   
    dibujar_toolbox();
    toolbox.revalidate();
      
     PanelBoard.add( tablero, null);
     PanelBoard.setSize(tablero.getSize());
           //Poner Imagen de Fondo en el PanelBoard
 
  
    }
    
    
   public void dibujar_toolbox(){
   
   String pawnW  = "\u2659";
   String kingW  = "\u2654";
   String queenW = "\u2655";
   String rookW  = "\u2656";
   String bishopW = "\u2657";
   String knightW = "\u2658";
 
   //Black set
   String pawnB  = "\u265F";
   String kingB  = "\u265A";
   String queenB = "\u265B";
   String rookB  = "\u265C";
   String bishopB = "\u265D";
   String knightB = "\u265E";
   
   String [] piece = new String[] {pawnW,kingW,queenW,rookW,bishopW,knightW,pawnB,
                                  kingB,queenB,rookB,bishopB,knightB};
   
  
   
   
    for (int i=0; i<piece.length; i++){
     int fontsize = 30 ;
     JToggleButton nuevo = new JToggleButton();
     nuevo.setFont(new Font("TimesRoman", Font.PLAIN,fontsize));
     nuevo.setText(piece[i]);
     nuevo.setToolTipText("Seleccionar "+tablero.get_piece_name(piece[i]));
    nuevo.addActionListener(new ActionListener( ) {
      public void actionPerformed(ActionEvent ev) {
          JToggleButton selected = (JToggleButton)ev.getSource();
          SelectedPiece = selected.getText();
        
      }});

     bg.add(nuevo);
     
     
     toolbox.add(nuevo,null);
     
       
       }
   
   }


    
     
     
   
   

  
    @Override
    public void mouseClicked(MouseEvent e) {
       if(e.getSource() == tablero){
       Graphics g=this.getGraphics();
           if(SelectedPiece !=null){
              int x = e.getX();
              int y = e.getY();
              int i=tablero.posinv(x);
              int j=tablero.posinv(y);
              if(!SelectedPiece.equals("Clean")){
                    tablero.piece[j*8+i]= tablero.get_piece(SelectedPiece);
                 }
              else{
                 tablero.piece[j*8+i] =' ';
              }
              
              tablero.update(g);
             
           }
           if(e.getButton()==MouseEvent.BUTTON3){
              int x = e.getX();
              int y = e.getY();
              int i=tablero.posinv(x);
              int j=tablero.posinv(y);
              Graphics gr = tablero.getGraphics();
           if(tablero.piece[j*8+i] == ' ' ){
     gr.setColor(Color.green);
     gr.fillRect(tablero.pos(i),tablero.pos(j),tablero.width,tablero.width);
           }
       }
          if(e.getButton() == MouseEvent.BUTTON1){
               Graphics gr = tablero.getGraphics();
              int x = e.getX();
              int y = e.getY();
              int i=tablero.posinv(x);
              int j=tablero.posinv(y);
              if(tablero.piece[j*8+i] == ' ' ){
           if (tablero.isDark(i,j)) {
           gr.setColor(tablero.darkSquare);
        } else {
           gr.setColor(tablero.lightSquare); 
        } 
     
    
     gr.fillRect(tablero.pos(i),tablero.pos(j),tablero.width,tablero.width);
          
          }}
    }
    
    }

    @Override
    public void mousePressed(MouseEvent e) {
  
        if( e.getSource() == tablero){
         Graphics g=this.getGraphics();
         int x = e.getX();
         int y = e.getY();
         int i=tablero.posinv(x);
         int j=tablero.posinv(y);
      if (i>=8 || j>=8) {
         return;
      }
      //  do nothing if square is empty
      if (tablero.piece[j*8+i]==' ') {
         return;
      }
      //  do nothing if square is not one of the
      //  pieces of the color whose turn it is
    /*  if (tablero.whiteTurn!=tablero.isWhite(tablero.piece[j*8+i])) {
         return;
      }*/
      
      // start dragging a piece      
      tablero.dragging=true;
      tablero.temp=false;
      tablero.dragCol=i;
      tablero.dragRow=j;
      tablero.dragPiece=tablero.piece[j*8+i];
      // highlight the selected square in red
      tablero.drawSquare(g,i,j,true);
      return;
    }
    
    }

    @Override
    public void mouseReleased(MouseEvent e) {
         if( e.getSource() == tablero){
     Graphics g=this.getGraphics();
     int x = e.getX();
     int y = e.getY(); 
     int i=tablero.posinv(x);
      int j=tablero.posinv(y);
      if (tablero.dragging) {
         if (tablero.temp && i>=0 && j<8
                  && !(i==tablero.dragCol && j==tablero.dragRow)) {
            // make the temporary move permanent
            tablero.drawSquare(g,tablero.tempCol,tablero.tempRow,false);
            // remove the piece from its old position
            tablero.piece[tablero.dragRow*8+tablero.dragCol]=' ';
             // place piece in its new position
            tablero.piece[j*8+i]=tablero.dragPiece;
            tablero.drawSquare(g,i,j,false);
            // change the turn
        //    tablero.whiteTurn=!tablero.whiteTurn;
         }
         // remove highlighting on old position
         tablero.drawSquare(g,tablero.dragCol,tablero.dragRow,false);
         tablero.temp=false;
         tablero.dragging=false;
      }
      return;
    }
    }

    @Override
    public void mouseEntered(MouseEvent e) {
     //
    }

    @Override
    public void mouseExited(MouseEvent e) {
        //Do nothing
    }

    @Override
    public void mouseDragged(MouseEvent e) {
         if( e.getSource() == tablero){
   //  System.out.print("Mouse dragged");
        Graphics g=this.getGraphics();
       int x = e.getX();
       int y = e.getY();
       int i=tablero.posinv(x);
       int j=tablero.posinv(y);
       if (tablero.dragging) {
         // has nothing changed from last time?
         if (tablero.temp && i==tablero.tempCol && j==tablero.tempRow) {
            return ;
         }
         if (tablero.temp) {
            // clear the previous temporary move
            tablero.drawSquare(g,tablero.tempCol,tablero.tempRow,false);
            tablero.temp=false;
         }
         // check for legal move 
         if (tablero.legalMove(i,j)) {
            // update new position to show the piece
            tablero.temp=true;
            tablero.tempCol=i;
            tablero.tempRow=j;
            tablero.drawSquare(g,i,j,true);
         }
      }
      return ;
    }
    }

    @Override
    public void mouseMoved(MouseEvent e) {
       // throw new UnsupportedOperationException("Not supported yet.");
    }


    /** This method is called from within the init() method to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jPanel2 = new javax.swing.JPanel();
        PanelBoard = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        jLabel13 = new javax.swing.JLabel();
        jLabel14 = new javax.swing.JLabel();
        jLabel15 = new javax.swing.JLabel();
        jLabel16 = new javax.swing.JLabel();
        jLabel17 = new javax.swing.JLabel();
        toolbox = new javax.swing.JPanel();
        jPanel3 = new javax.swing.JPanel();
        jPanel4 = new javax.swing.JPanel();
        jToggleButton1 = new javax.swing.JToggleButton();
        jToggleButton2 = new javax.swing.JToggleButton();
        jButton1 = new javax.swing.JButton();
        Ordenarbtn = new javax.swing.JButton();

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 100, Short.MAX_VALUE)
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 100, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 100, Short.MAX_VALUE)
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 100, Short.MAX_VALUE)
        );

        PanelBoard.setBackground(new java.awt.Color(115, 165, 183));
        PanelBoard.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));
        PanelBoard.setName("PanelBoard"); // NOI18N
        PanelBoard.setPreferredSize(new java.awt.Dimension(452, 452));

        jLabel2.setFont(new java.awt.Font("SansSerif", 1, 14));
        jLabel2.setText("8");

        jLabel3.setFont(new java.awt.Font("SansSerif", 1, 14));
        jLabel3.setText("7");

        jLabel4.setFont(new java.awt.Font("SansSerif", 1, 14));
        jLabel4.setText("6");

        jLabel5.setFont(new java.awt.Font("SansSerif", 1, 14));
        jLabel5.setText("5");

        jLabel6.setFont(new java.awt.Font("SansSerif", 1, 14));
        jLabel6.setText("4");

        jLabel7.setFont(new java.awt.Font("SansSerif", 1, 14));
        jLabel7.setText("3");

        jLabel8.setFont(new java.awt.Font("SansSerif", 1, 14));
        jLabel8.setText("2");

        jLabel9.setFont(new java.awt.Font("SansSerif", 1, 14));
        jLabel9.setText("1");

        jLabel10.setFont(new java.awt.Font("SansSerif", 1, 14));
        jLabel10.setText("A");

        jLabel11.setFont(new java.awt.Font("SansSerif", 1, 14));
        jLabel11.setText("B");

        jLabel12.setFont(new java.awt.Font("SansSerif", 1, 14));
        jLabel12.setText("C");

        jLabel13.setFont(new java.awt.Font("SansSerif", 1, 14));
        jLabel13.setText("D");

        jLabel14.setFont(new java.awt.Font("SansSerif", 1, 14));
        jLabel14.setText("E");

        jLabel15.setFont(new java.awt.Font("SansSerif", 1, 14));
        jLabel15.setText("F");

        jLabel16.setFont(new java.awt.Font("SansSerif", 1, 14));
        jLabel16.setText("G");

        jLabel17.setFont(new java.awt.Font("SansSerif", 1, 14));
        jLabel17.setText("H");

        javax.swing.GroupLayout PanelBoardLayout = new javax.swing.GroupLayout(PanelBoard);
        PanelBoard.setLayout(PanelBoardLayout);
        PanelBoardLayout.setHorizontalGroup(
            PanelBoardLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(PanelBoardLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(PanelBoardLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(PanelBoardLayout.createSequentialGroup()
                        .addGap(10, 10, 10)
                        .addComponent(jLabel10)
                        .addGap(44, 44, 44)
                        .addComponent(jLabel11)
                        .addGap(45, 45, 45)
                        .addComponent(jLabel12)
                        .addGap(44, 44, 44)
                        .addComponent(jLabel13)
                        .addGap(40, 40, 40)
                        .addComponent(jLabel14)
                        .addGap(44, 44, 44)
                        .addComponent(jLabel15)
                        .addGap(50, 50, 50)
                        .addComponent(jLabel16)
                        .addGap(52, 52, 52)
                        .addComponent(jLabel17)
                        .addContainerGap())
                    .addGroup(PanelBoardLayout.createSequentialGroup()
                        .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 18, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap(474, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, PanelBoardLayout.createSequentialGroup()
                        .addGroup(PanelBoardLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel9, javax.swing.GroupLayout.PREFERRED_SIZE, 8, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel8, javax.swing.GroupLayout.PREFERRED_SIZE, 8, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, 8, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel6)
                            .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 18, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(PanelBoardLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 8, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, PanelBoardLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel3)
                                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, PanelBoardLayout.createSequentialGroup()
                                        .addComponent(jLabel2)
                                        .addGap(37, 37, 37)))))
                        .addContainerGap())))
        );
        PanelBoardLayout.setVerticalGroup(
            PanelBoardLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(PanelBoardLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel2)
                .addGap(30, 30, 30)
                .addComponent(jLabel3)
                .addGap(36, 36, 36)
                .addComponent(jLabel4)
                .addGap(36, 36, 36)
                .addComponent(jLabel5)
                .addGap(35, 35, 35)
                .addComponent(jLabel6)
                .addGap(41, 41, 41)
                .addComponent(jLabel7)
                .addGap(37, 37, 37)
                .addComponent(jLabel8)
                .addGap(44, 44, 44)
                .addComponent(jLabel9)
                .addGap(25, 25, 25)
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(PanelBoardLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel10)
                    .addComponent(jLabel11)
                    .addComponent(jLabel12)
                    .addComponent(jLabel13)
                    .addComponent(jLabel14)
                    .addComponent(jLabel15)
                    .addComponent(jLabel16)
                    .addComponent(jLabel17))
                .addGap(17, 17, 17))
        );

        toolbox.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));
        toolbox.setLayout(new java.awt.GridLayout(1, 0));

        jPanel3.setLayout(new java.awt.GridLayout(1, 0));

        jPanel4.setLayout(new java.awt.GridLayout(1, 0));

        jToggleButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Resources/pointer.png"))); // NOI18N
        jToggleButton1.setToolTipText("Seleccionar puntero");
        jToggleButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jToggleButton1ActionPerformed(evt);
            }
        });
        jPanel4.add(jToggleButton1);

        jToggleButton2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Resources/xicon.png"))); // NOI18N
        jToggleButton2.setToolTipText("Eliminar fichas ");
        jToggleButton2.setPreferredSize(new java.awt.Dimension(73, 53));
        jToggleButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jToggleButton2ActionPerformed(evt);
            }
        });
        jPanel4.add(jToggleButton2);

        jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Resources/clean.png"))); // NOI18N
        jButton1.setToolTipText("Limpiar el tablero");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });
        jPanel4.add(jButton1);

        Ordenarbtn.setFont(new java.awt.Font("Copperplate Gothic Light", 0, 12)); // NOI18N
        Ordenarbtn.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Resources/chess-icon.png"))); // NOI18N
        Ordenarbtn.setText("Ordenar Piezas");
        Ordenarbtn.setToolTipText("");
        Ordenarbtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                OrdenarbtnActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(PanelBoard, javax.swing.GroupLayout.PREFERRED_SIZE, 508, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(187, 187, 187)
                        .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, 176, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, 172, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(toolbox, javax.swing.GroupLayout.PREFERRED_SIZE, 171, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(Ordenarbtn))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addGap(19, 19, 19)
                        .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(Ordenarbtn, javax.swing.GroupLayout.PREFERRED_SIZE, 43, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(toolbox, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addComponent(PanelBoard, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 495, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(19, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
   Graphics g=this.getGraphics();
   for(int i=0; i<tablero.piece.length;i++){
   tablero.piece[i]=' ';
  
   }
    tablero.update(g);
}//GEN-LAST:event_jButton1ActionPerformed

private void jToggleButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jToggleButton1ActionPerformed
             SelectedPiece=null;
             bg.clearSelection();
}//GEN-LAST:event_jToggleButton1ActionPerformed

private void jToggleButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jToggleButton2ActionPerformed
            SelectedPiece = "Clean";
}//GEN-LAST:event_jToggleButton2ActionPerformed

private void OrdenarbtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_OrdenarbtnActionPerformed
   tablero.piece = tablero.startposition.clone();
   tablero.update(this.getGraphics());
}//GEN-LAST:event_OrdenarbtnActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton Ordenarbtn;
    private javax.swing.JPanel PanelBoard;
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JToggleButton jToggleButton1;
    private javax.swing.JToggleButton jToggleButton2;
    private javax.swing.JPanel toolbox;
    // End of variables declaration//GEN-END:variables
    private String SelectedPiece; 
    ButtonGroup bg = new ButtonGroup();

}
